<template>
    <div class="r_main">
        <div class="tabIn">
            <div class="tab">
                我的礼物
            </div>
            <div class="operate">
                <div>
                    当前共收到礼物<strong>{{ total_num }}</strong>件，
                    合计<strong>{{ total_price }}</strong>主题币
                </div>
                <div class="btn2" @click="goPage">
                    兑换
                </div>
            </div>
        </div>
        <div class="form_con">
            <div class="type">
                <span @click="getType(1)" :class="{ active: op == 1 }">我收到的礼物</span>
                <span @click="getType(2)" :class="{ active: op == 2 }">我送出的礼物</span>
            </div>
            <div class="outer" v-if="!$store.getters.isMobile">
                <el-table border :data="tableData" style="width: 100%">
                    <el-table-column prop="time" align="center" label="打赏时间">
                    </el-table-column>
                    <el-table-column prop="user_nickname" :label="uname" align="center" width="180" />
                    <el-table-column prop="image" align="center" label="礼物">
                        <template slot-scope="scope">
                            <img style="max-width: 100px;max-height: 100px;" :src="scope.row.image" alt="">
                        </template>
                    </el-table-column>
                    <el-table-column prop="nums" align="center" label="数量" />
                    <el-table-column prop="title" align="center" label="来源" />
                    <el-table-column prop="price" align="center" label="价值（主题币）" />
                </el-table>
            </div>
            <div class="outer_mob" v-else>
                <div class="info" v-for="item in tableData" :key="item.id">
                    <div>
                        <span>打赏时间</span>
                        <span>{{ item.time }}</span>
                    </div>
                    <div>
                        <span>{{ uname }}</span>
                        <span>{{ item.user_nickname }}</span>
                    </div>
                    <div>
                        <span>礼物</span>
                        <div>
                            <img style="max-width: 100px;max-height: 100px;" :src="item.image" alt="">
                        </div>
                    </div>
                    <div>
                        <span>数量</span>
                        <span>{{ item.nums }}</span>
                    </div>
                    <div>
                        <span>来源</span>
                        <span>{{ item.title }}</span>
                    </div>
                    <div>
                        <span>价值（主题币）</span>
                        <span>{{ item.price }}</span>
                    </div>
                </div>
                <div v-if="tableData.length == 0">
                    <el-empty description="没有内容了"></el-empty>
                </div>
            </div>
        </div>
    </div>

</template>
<script>
import t1 from "@/assets/img/t1.png"
export default {
    data() {
        return {
            tableData: [],
            op: 1,
            pageNum: 1,
            totalPage: 1,
            showChud: true,
            loading: false,
            total_price: '',
            total_num: '',
            uname: '礼物来源'
        }
    },
    computed: {
        path() {
            return this.$route.path
        }
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },
    created() {
        this.getData()
    },
    methods: {
        getType(t) {
            this.op = t
            this.uname = this.op == 1 ? '礼物来源' : '礼物接收'
            this.tableData = []
            this.pageNum = 1
            this.totalPage = 1
            this.getData()
        },
        goPage() {
            this.$router.push('/moneyBag/discount')
        },
        confirm(item) {
            console.log(item);

        },
        getData() {
            let params = {
                page: this.pageNum,
                op: parseInt(this.op)
            }
            this.$api.getGiftlog(params).then(response => {
                console.log(response);
                if (response.data.code == 1) {
                    const res = response.data.data
                    this.totalPage = res.list.last_page
                    this.tableData = this.tableData.concat(res.list.data);
                    this.loading = false
                    this.total_price = res.price
                    this.total_num = res.total
                }

            })
        },
        load() {
            console.log("处理触底");
            var page = this.pageNum
            let that = this
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                if (this.showChud) {
                    this.showChud = false
                    this.$message({
                        type: 'info',
                        message: '已经是最后一页了~',
                        onClose: () => {
                            setTimeout(() => {
                                that.showChud = true
                            }, 5000)
                        }
                    })
                }
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getData()
        },
        onsubmit() {
            console.log(this.form);

        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.r_main {
    width: 100%;

    .user {
        width: 100%;
        height: 200px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        padding: 0 30px;
        overflow: hidden;
        background: linear-gradient(to right, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));

        .bgg {
            position: absolute;
            width: 100%;
            height: auto;
            z-index: -1;

        }

        .left {
            display: flex;
            color: #fff;
            align-items: center;

            .avatar {
                width: 150px;
                height: 150px;
                margin-right: 27px;
                flex-shrink: 0;
                border-radius: 50%;
                overflow: hidden;

                img {
                    object-fit: cover;
                    width: 100%;
                    height: 100%;
                }
            }

            .info {
                .nane {
                    font-weight: bold;
                    font-size: 30px;
                    color: #FFFFFF;
                    margin-bottom: 13px;
                }

                .data {
                    display: flex;
                    align-items: center;
                    margin-bottom: 13px;

                    .line {
                        height: 18px;
                        display: block;
                        width: 2px;
                        background-color: #fff;
                        margin: 0 18px;
                    }

                    >div {
                        font-weight: 400;
                        font-size: 18px;
                        color: #999999;

                        >span {
                            color: #FFFFFF;
                        }
                    }
                }

                .address {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10px;
                    font-weight: 400;
                    font-size: 16px;
                    color: #999999;

                    .line {
                        margin: 0 18px;
                        display: block;
                        height: 16px;
                        width: 2px;
                        background-color: #999;
                    }
                }

                .sign {
                    font-weight: 400;
                    font-size: 16px;
                    color: #FFFFFF;
                }
            }
        }

        .right {
            height: 100%;
            padding: 28px 0 38px;
            font-weight: 400;
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            flex-direction: column;
            font-size: 20px;
            color: #FFFFFF;

            .share {
                cursor: pointer;
                display: flex;
                align-items: center;
                justify-content: center;

                img {
                    width: 28px;
                    height: auto;
                    margin-left: 11px;
                }
            }

            .btn {
                display: flex;
                align-items: center;
                justify-content: center;

                button {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    width: 120px;
                    height: 48px;
                    background: #F98951;
                    border-radius: 24px;
                    opacity: 0.9;
                    margin-left: 26px;
                    font-weight: 400;
                    font-size: 20px;
                    color: #FFFFFF;
                    border: none;

                    &:nth-child(2) {
                        background: #1068E7;
                    }
                }
            }
        }
    }

    .tabIn {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 23px 0;
        background-color: #E5E5E5;
        position: sticky;
        top: 99px;
        z-index: 99;
        padding: 0 23px;
        height: 60px;

        // border-top: 0.05rem solid #E8E8E8;
        .tab {
            font-weight: bold;
            font-size: 24px;
            color: #1068E7;
        }

        .btn2 {
            cursor: pointer;
            font-weight: 400;
            font-size: 14px;
            color: #FFFFFF;
            width: 82px;
            text-align: center;
            line-height: 34px;
            height: 34px;
            background: #1068E7;
            border-radius: 17px;
        }

    }

    .form_con {
        .type {
            position: sticky;
            top: 159px;
            font-weight: 400;
            font-size: 20px;
            color: #666666;
            padding: 0 30px;
            z-index: 9;
            background-color: #fff;
            height: 90px;
            display: flex;
            align-items: center;

            >span {
                margin-right: 44px;
                cursor: pointer;
            }

            .active {
                font-weight: bold;
                font-size: 20px;
                color: #2877E9;
            }
        }

        min-height: 500px;
        // overflow-y: auto;
    }
}

.outer {
    display: flex;
    align-items: flex-start;
    padding-bottom: 20px;

    ::v-deep .el-table th.el-table__cell {
        background-color: #E7F1FE;
    }

    .y1 {
        width: 100%;
        display: flex;
        flex-wrap: wrap;

        >div {
            width: calc(50% - 12.5px);

            &:nth-child(2n) {
                margin-left: 25px;
            }
        }
    }

    .list {
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
        width: 100%;

        .title {
            display: flex;
            align-items: center;
            font-weight: 400;
            font-size: 18px;
            color: #000000;

            img {
                width: 16px;
                height: auto;
                margin-right: 16px;
            }

            .name {
                width: 700px;
            }
        }

        .set {
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex: 1;

            .data {
                font-size: 16px;
                color: #999;
                display: flex;
                align-items: center;

                >span {
                    display: inline-block;
                    flex-shrink: 0;
                }

                .dz {
                    margin-right: 15px;
                    width: 100px;
                    text-align: center;
                }

                .line {
                    width: 2px;
                    height: 15px;
                    background-color: #999;
                }

                .nums {
                    width: 120px;
                    text-align: center;
                }

                .nickname {
                    margin-left: 15px;
                }
            }

            .btn {
                display: flex;

                .price {
                    font-size: 20px;
                    color: #D31B23;
                    margin-right: 50px;
                }

                button {
                    width: 80px;
                    height: 30px;
                    background-color: #1169E5;
                    border: none;
                    border-radius: 5px;
                    color: #fff;
                }
            }
        }
    }
}

.operate {
    display: flex;
    align-items: center;
    font-weight: 400;
    font-size: 16px;
    color: #3F3A39;

    >div {
        margin-left: 20px;
    }

    ::v-deep .el-date-editor.el-input {
        width: 180px;
    }

    ::v-deep .el-select {
        width: 180px;
    }
}

@media screen and (max-width:768px) {
    .r_main {
        .tabIn {
        height: 40px;
        padding: 0 20px;

        .tab {
            font-size: 15px;
        }
        .operate{
            font-size: 12px;

        .btn2 {
            font-size: 12px;
            width: 60px;
            height: 20px;
            line-height: 20px;
        }
        }
    }
    .form_con{
        .type{
            margin: 10px;
            font-size: 16px;
            .active{
            font-size: 16px;
        }
        }
       
    }
    }
    .outer_mob{
        padding:10px 20px;
        .info{
            border: 1px solid #ccc;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 10px;
        >div{
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            margin-bottom: 10px;
            &:last-child{
                margin: 0;
            }
            >div{
                img{
                    width: 30px;
                    height:30px;
                }
            }
            >span{
                display: inline-block;
                font-size: 13px;
                &:first-child{
                    font-size: 14px;
                    font-weight: bold;
                    width: 100px;
                }
            }
        }
           
        }
    }
}
</style>